package com.waiting.leetcode;

/**
 * @Description
 * @Author bjweitingting
 * @Date 2019/3/8
 **/
public class CountingBits338 {
    public static void main(String[] args) {
        System.out.println(2 & (2 - 1));
    }

    public int[] countBits(int num) {
        int[] result = new int[num + 1];
        result[0] = 0;
        if (num < 1) {
            return result;
        }
        result[1] = 1;
        int max = 0;
        for (int i = 1; i <= num; i++) {
            if ((i & (i - 1)) == 0) {
                max = i;
                result[i] = 1;
            } else {
                result[i] = result[max] + result[i - max];
            }
        }
        return result;
    }
}
